package com.gxa.uhome.service.impl;

import com.gxa.uhome.mapper.StationMapper;
import com.gxa.uhome.pojo.Station;
import com.gxa.uhome.service.StationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: fanyouzhao
 * @date: 14:10 2021/6/7
 */
@Transactional(rollbackFor = Throwable.class)
@Service("stationService")
public class StationServiceImpl implements StationService {
    @Resource
    private StationMapper stationMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.READ_COMMITTED)
    public List<Station> selectAll() {
        return stationMapper.selectAll();
    }

    @Override
    public List<Station> selectByPage(Integer page, Integer size) {
        page = page!=null && page>=1 ? (page - 1) * size : 0;
        return stationMapper.selectByPage(page, size);
    }

    @Override
    public Boolean add(Station station) {
        return stationMapper.insert(station);
    }

    @Override
    public Integer getCount() {
        return stationMapper.getCount();
    }

    @Override
    public Boolean del(Integer id) {
        return stationMapper.del(id);
    }

    @Override
    public List<Station> selectLikeNameByPage(String name, Integer page, Integer size) {
        name = name==null || "".equals(name) ? "%%" : "%"+name+"%";
        page = page!=null && page>=1 ? (page - 1) * size : 0;
        return stationMapper.selectLikeNameByPage(name, page, size);
    }

    @Override
    public Integer getCountLikeName(String name) {
        name = name==null || "".equals(name) ? "%%" : "%"+name+"%";
        return stationMapper.getCountLikeName(name);
    }

    @Override
    public Boolean update(Station station) {
        return stationMapper.update(station);
    }

    @Override
    public Station selectByName(String name) {
        return stationMapper.selectByName(name);
    }

    @Override
    public Station selectById(Integer id) {
        return stationMapper.selectById(id);
    }
}
